package com.server;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.views.xslt.ArrayAdapter;

import com.dbserver.Condb;

public class CountService {
	public int getCounts(String countSql)
	  {   
		//处理结果集
		Condb condb=new Condb();
		int count=0;
	  	try {
	  	    
	  	  	ResultSet rs=condb.query(countSql);
			if(rs.next())
			{
				count=rs.getInt(1);
			}
			rs.close();
			condb.close();
		} catch (SQLException e) {
			condb.close();
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	  }
	public int getAllCounts(String countSql)
	  {   
		//处理结果集
		Condb condb=new Condb();
		int count=0;
	  	try {
	  	    
	  	  	ResultSet rs=condb.query(countSql);
			while(rs.next())
			{
				count+=rs.getInt(1);
			}
			rs.close();
			condb.close();
		} catch (SQLException e) {
			condb.close();
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return count;
	  }
	
	public List getAllValues(String countSql)
	  {   
		//处理结果集
		Condb condb=new Condb();
		List values=new ArrayList();
	  	try {
	  	    
	  	  	ResultSet rs=condb.query(countSql);
			while(rs.next())
			{
				values.add(rs.getString(1));
			}
			rs.close();
			condb.close();
		} catch (SQLException e) {
			condb.close();
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return values;
	  }
}
